﻿Public Class QL_SP_Xuat
    Dim xctBL As XuatChiTietBL
    Public ma As String = ""

    Private Sub loadDGV(ByVal _dieukien As String)
        xctBL = New XuatChiTietBL
        Dim list As List(Of XuatChiTietDT)
        list = xctBL.GetData(_dieukien)
        dgvDS_XUAT.DataSource = list
    End Sub
    Private Sub LoadCBOX()
        xctBL = New XuatChiTietBL
        Dim list As New List(Of XuatChiTietDT)
        list = xctBL.GetData(" WHERE MaXuat = '" + ma + "'")
        cbLoai.DataSource = list
        cbLoai.DisplayMember = "MaLoai"
        cbLoai_Tong.DataSource = list
        cbLoai_Tong.DisplayMember = "MaLoai"
        list = New List(Of XuatChiTietDT)
        list = xctBL.GetData(" WHERE MaXuat <> '" + ma + "'")
        cbNgay.DataSource = list
        cbNgay.DisplayMember = "Ma"
        cbNgay.ValueMember = "Ma"
    End Sub

    Private Sub QL_SP_Xuat_Ngay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadDGV(" WHERE MaXuat = '" + ma + "'")
        LoadCBOX()
    End Sub

    'Thong ke so luong
    Private Sub cbAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbAll.CheckedChanged
        If cbAll.Checked = True Then
            cbLoai_Tong.Enabled = False
        Else
            cbLoai_Tong.Enabled = True
        End If
    End Sub
    Private Sub btnExec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExec.Click
        If cbAll.Checked = True Then
            'lam form thong ke
        Else
            Dim tong As Double = xctBL.GetTong(ma, cbLoai_Tong.SelectedValue)
            txtTong.Text = tong.ToString()
        End If
    End Sub

    Private Sub cbLoai_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbLoai.SelectedIndexChanged
        If cbLoai.Enabled = True Then
            loadDGV(" WHERE MaXuat = '" + ma + "' AND MaLoai = " & Convert.ToInt32(cbLoai.SelectedText))
        End If
    End Sub

    Private Sub cbKhac_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbKhac.CheckedChanged
        If cbKhac.Checked = True Then
            cbNgay.Enabled = True
            cbNgay.Focus()
            cbLoai.Enabled = False
        Else
            cbNgay.Enabled = False
            cbLoai.Enabled = True
            loadDGV(" WHERE MaXuat = '" + ma + "'")
        End If
    End Sub

    Private Sub cbNgay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbNgay.SelectedIndexChanged
        If cbKhac.Checked = True Then
            loadDGV(" WHERE MaXuat = '" + cbNgay.SelectedValue.ToString() + "'")
        End If
    End Sub
End Class